package com.hc.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.hc.bean.PageBean;
import com.hc.domain.Brand;
import com.hc.domain.Province;
import com.hc.domain.query.ProvinceQuery;
import com.hc.mapper.ProvinceMapper;
import com.hc.service.ProvinceService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service("provinceService")
public class ProvinceServiceImpl implements ProvinceService {

    @Resource
    private ProvinceMapper provinceMapper;

    @Override
    public PageBean<Province> getPage(ProvinceQuery provinceQuery, Integer pageNum, Integer pageSize) {
        Page<Province> page = PageHelper.startPage(pageNum, pageSize);
        provinceMapper.selectPage(provinceQuery);
        PageBean<Province> res = new PageBean<>(page);
        return res;
    }

    @Override
    public Province getById(Integer provinceId) {
        Province province = provinceMapper.selectById(provinceId);
        return province;
    }

    @Override
    public boolean add(Province province) {
        int res = provinceMapper.insert(province);
        return res == 1;
    }

    @Override
    public boolean update(Province province) {
        int res = provinceMapper.update(province);
        return res == 1;
    }

}
